<?php
    session_start();

    $connect = mysqli_connect('localhost','root','root','db_info');
    $sql = "select * from tb_article where isRecommend = 1 limit 0,3";
    $query = mysqli_query($connect,$sql);
    $list = array();
    while($result = mysqli_fetch_assoc($query)){
        $list[] = $result;
    }
//    print_r($list)
?>
<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>index</title>
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/index.css">
</head>
<body>
<?php include_once 'header.php'?>
<div id="box" style="margin-top: 45px">
    <ul id="img">
        <li class="g" style="z-index: 9999" id="img1">
            <div class="innerText">
                <p>升级正当时</p>
                <p>动力源自 NVIDIA® GEFORCE™</p>
            </div>
        </li>
        <li class="g" style="opacity: 0;" id="img2">
            <div class="innerText">
                <p>强者制胜</p>
                <p>GEFORCE RTX™ 3060 Ti</p>
            </div>
        </li>
        <li class="g" style="opacity: 0;" id="img3">
            <div class="innerText">
                <p>RTX. IT'S ON.</p>
                <p>现已支持光线追踪和 DLSS 技术</p>
            </div>
        </li>
        <li class="g" style="opacity: 0;" id="img4">
            <div class="innerText">
                <p>现已支持光线追踪和 DLSS 技术</p>
            </div>
        </li>
    </ul>
    <ul id="dian">
        <li class="d" style="background-color:#76B900;"></li>
        <li class="d"></li>
        <li class="d"></li>
        <li class="d"></li>
    </ul>
</div>
<main>
    <div class="infoBTitle container">
        <p>最新资讯 <a href="javascript:;" style="float:right;color: #fff;text-decoration: none">查看更多</a></p>
    </div>
    <div class="infoList container" style="color: #fff;">
        <div class="infoBox" v-for="(item , index) in infoList" :key="index">

            <div class="infoTitle">
                {{item.title}}
            </div>
            <div class="infoIntroduction qudiao">
                {{item.introduction}}
            </div>
            <div class="goBuy">
                <a class="buyBtn" :href="item.url">
                    查看详情
                </a>
            </div>
        </div>
    </div>

</main>

<?php include_once 'footer.php'?>
<?php include_once 'loginLayout.php'?>
</body>
<script src="./js/tools.js"></script>
<script src="./js/header.js"></script>
<script src="./js/carousel.js"></script>
<script src="./js/vue-2.6.12.js"></script>
<!--<script src="./js/info.js"></script>-->
<script src="./js/jquery-3.5.1.js"></script>
<script>
    const infoList = [
        <?php

            for($i = 0;$i < count($list);$i++){
            ?>

        {
            title: '<?php echo $list[$i]['title']?>',
            introduction: '<?php echo substr($list[$i]['text'],0,100)."..."; ?>',
            url: '../info.php?id=<?php echo $list[$i]['id']?>'
        },
        <?php
        }
        ?>
    ]
    const vm = new Vue({
        el: 'main',
        data: {
            infoList
        }
    })


    $('#login').click(function(){
        window.location.href = 'login.php'
    })
    $('#logout').click(function(){
        $.post('connect.php',{
            type: 'logout'
        },function (data){
            if(data === '1'){
                location.reload()
            }
        })
    })
    $('#register').click(function(){
        window.location.href = 'register.html'
    })
</script>
<script type="text/javascript">
    $(function(){
        var list = $(".qudiao");//获取class所有元素
        for(var i = 0 ; i< list.length ; i ++ ){
            var s = $(list[i]).text();//获取里面的博客摘要内容
            var dd=s.replace(/<[^>]+>/g,"");//截取html标签
            var dds=dd.replace(/&nbsp;/ig,"");//截取空格等特殊标签

            $(list[i]).text("");//清空里面内容
            $(list[i]).text(dds.substring(0,200))//截取200个字符
        }
    })
</script>
</html>